package(default_visibility = ["//modules/benchmarks:__subpackages__"])

load("//tools:defaults.bzl", "ng_module", "ng_rollup_bundle", "ts_library")
load("@npm_bazel_typescript//:index.bzl", "ts_devserver")
load("//modules/benchmarks:benchmark_test.bzl", "benchmark_test")

ng_module(
    name = "application_lib",
    srcs = glob(
        ["**/*.ts"],
        exclude = ["**/*.spec.ts"],
    ),
    deps = [
        "//packages:types",
        "//packages/common",
        "//packages/core",
        "//packages/localize/init",
        "//packages/platform-browser",
        "@npm//rxjs",
    ],
)

ts_library(
    name = "perf_lib",
    testonly = 1,
    srcs = ["benchmark_perf.spec.ts"],
    deps = [
        "//modules/e2e_util",
        "@npm//protractor",
    ],
)

ng_rollup_bundle(
    name = "bundle",
    entry_point = ":index_aot.ts",
    deps = [
        ":application_lib",
        "@npm//rxjs",
    ],
)

ts_devserver(
    name = "prodserver",
    index_html = "index.html",
    port = 4200,
    static_files = [
        "@npm//:node_modules/zone.js/dist/zone.js",
    ],
    deps = [
        ":bundle.min.js",
    ],
)

ts_devserver(
    name = "devserver",
    entry_module = "angular/modules/benchmarks/src/expanding_rows/index_aot",
    # Uncomment this to run devserver. This is due to limitation of ts_devserver
    # that produces `index.html` by default so there cannot be two ts_devserver
    # rules in a single Bazel package.
    # index_html = "index.html",
    port = 4200,
    scripts = [
        "@npm//:node_modules/tslib/tslib.js",
        "//tools/rxjs:rxjs_umd_modules",
    ],
    static_files = [
        "@npm//:node_modules/zone.js/dist/zone.js",
    ],
    deps = [":application_lib"],
)

benchmark_test(
    name = "perf",
    server = ":prodserver",
    deps = [
        ":perf_lib",
    ],
)
